package com.ncp.servlet.cart;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ncp.model.biz.cart.HandlePaymentBiz;
import com.ncp.model.biz.order.ManageAddressBiz;
import com.ncp.model.entity.cart.OrderBasicBean;
import com.ncp.model.entity.order.Receiver;

public class ConfirmPaymentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String userLoginName = (String)request.getSession().getAttribute("LoginName");
		if("".equals(userLoginName)||userLoginName==null){
			out.print("<script language=javascript>alert('请登录！');window.location.replace('index.jsp');</script>"); 
		}else{
			this.confirmOrderInfo(request, response);
		}
	}
	
	public void confirmOrderInfo(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
		//获得orderID
		String orderID = request.getParameter("orderid");
		//System.out.println(orderID);
		//根据订单号获得该订单的数据
		HandlePaymentBiz handlePaymentBiz = new HandlePaymentBiz();
		OrderBasicBean orderBasicBean = handlePaymentBiz.getOrderInfoByOrderID(orderID);
		ManageAddressBiz manageAddressBiz = new ManageAddressBiz();
		Receiver receiver = manageAddressBiz.getReceiverByID(orderBasicBean.getReceiverID());
		orderBasicBean.setReceiverAddress(receiver.getAddress());
		orderBasicBean.setReceiverEMail(receiver.getEmail());
		orderBasicBean.setReceiverMobile(receiver.getMobile());
		orderBasicBean.setReceiverName(receiver.getName());
		orderBasicBean.setReceiverPhone(receiver.getPhone());
		orderBasicBean.setReceiverZip(receiver.getZip());
		request.setAttribute("orderbasicbean", orderBasicBean);
		//订单名称，显示在支付宝收银台里的“商品名称”里，显示在支付宝的交易管理的“商品名称”的列表里。
		String subject = "订单"+orderBasicBean.getOrderID();
		request.setAttribute("subject", subject);
		//订单描述、订单详细、订单备注，显示在支付宝收银台里的“商品描述”里
		String body = "我是测试商品，看到我表示测试成功了！";
		request.setAttribute("alibody", body);
		request.getRequestDispatcher("pages/cart/alipay/alipayto.jsp").forward(request, response);
		
}
}
